package com.gosophia.reportData.action;

import java.util.List;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.exception.BusinessException;
import com.gosophia.reportData.dto.ReportDetailDTO;
import com.gosophia.reportData.ws.ReportDataSearchWebService;
import com.gosophia.taskManagement.action.BaseMissionDetailAction;
import com.gosophia.taskManagement.dto.JobHandleRecordsDTO;
import com.gosophia.taskManagement.dto.MissionDTO;
import com.gosophia.taskManagement.ws.TaskManagementWebService;

@SuppressWarnings("serial")
@Scope("prototype")
@Controller("reportMissionDetailAction")
public class ReportMissionDetailAction extends BaseMissionDetailAction {

    @Autowired
    private ReportDataSearchWebService reportDataSearchWebService;
    
    @Autowired
    private TaskManagementWebService taskManagementWebService;

    private ReportDetailDTO reportDetailDTO;

    private List<JobHandleRecordsDTO> historyList;
    
    private MissionDTO missionDTO;

    @Override
    public String _execute() throws Exception {
        if (super.getMissionId() != null) {
            try {
                reportDetailDTO = reportDataSearchWebService
                        .findReportDataInformation(super.getMissionId());
            } catch (BusinessException e) {
                e.printStackTrace();
            }
            historyList = super.getHistoryList();
            for (JobHandleRecordsDTO handle : historyList) {
                if (handle.getJobType() != null) {
                    if (handle.getJobType().equals("发起")) {
                        handle.setContent("设定了 报送要求");
                    } else if (handle.getJobType().equals("上报")) {
                        handle.setContent("报送");
                    } else if (handle.getJobType().equals("审核")) {
                        if (handle.getJobState().equals("已退回")) {
                            handle.setContent("退回");
                        } else {
                            handle.setContent("通过");
                        }
                    }
                }
            }
        }
        System.out.println(JSONArray.fromObject(historyList).toString());
        return SUCCESS;
    }

    public ReportDetailDTO getReportDetailDTO() {
        return reportDetailDTO;
    }

    public void setReportDetailDTO(ReportDetailDTO reportDetailDTO) {
        this.reportDetailDTO = reportDetailDTO;
    }

    @Override
    public List<JobHandleRecordsDTO> getHistoryList() {
        return historyList;
    }

    @Override
    public void setHistoryList(List<JobHandleRecordsDTO> historyList) {
        this.historyList = historyList;
    }

	public MissionDTO getMissionDTO() {
		return missionDTO;
	}

	public void setMissionDTO(MissionDTO missionDTO) {
		this.missionDTO = missionDTO;
	}

}
